﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SushiSOAPServices.Dominio;
using NHibernate;

namespace SushiSOAPServices.Persistencia
{
    public class PersonaDAO : BaseDAO<Persona, int>
    {

        public Persona obtenerPersonaPorDNI(string dni)
        {

            using (ISession sesion = NHibernateHelper.ObtenerSesion())
            {
                string sentenciaSQL = "select u from Persona as u where u.NumDocIden = :dni";
                IQuery query = sesion.CreateQuery(sentenciaSQL);
                query.SetParameter("dni", dni);
                IList<Persona> lista = query.List<Persona>();

                if (lista.Count == 0)
                {
                    Persona person = null;
                    return person;
                }
                else
                {
                    return lista[0];
                }


            }

        }

    }
}